//
//  imageShowVC.m
//  照片墙
//
//  Created by 融易科技 on 2017/4/27.
//  Copyright © 2017年 糊糊糊. All rights reserved.
//

#import "imageShowVC.h"
@interface imageShowVC ()
@property (nonatomic, strong)SDCycleScrollView *scrollView;
@end

#define gscTag 100000

@implementation imageShowVC

-(SDCycleScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageNamesGroup:_picArray];
        _scrollView.autoScroll  = NO;
        _scrollView.gscAutoIndex = _displayIndex;
        _scrollView.infiniteLoop = NO;
        _scrollView.showPageControl = NO;
    }
    return _scrollView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUIView];
}

-(void)loadView{
    [super loadView];
    [self.view addSubview:self.scrollView];
    [self.view addSubview:_imageView];
}

- (void)setUIView{
    
    /*
     *这个是点击小图的时候过渡到大图的一个动画。
     */
    [UIView animateWithDuration:0.5 animations:^{
        _imageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        if (finished) {
            [_imageView removeFromSuperview];
            [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self.view);
            }];
        }
    }];
    
    __weak imageShowVC *weakSelf = self;
    ///点击大图的回调
    _scrollView.clickItemOperationBlock = ^(NSInteger currentIndex) {
        /*获取你当前的大图View
         ****因为你的大图是整个屏幕的所以直接用first 即可获取
         */
       SDCollectionViewCell *cell = [[weakSelf.scrollView.mainView visibleCells] firstObject];
        
        //当你点击的小图和你大图不是同一张时
        if (currentIndex != _displayIndex) {
            cell.imageView.tag  = currentIndex + gscTag;
            weakSelf.popB(weakSelf.view,cell.imageView);
        }else{
            //当你点击的小图和你大图是同一张时
            weakSelf.popTwoB(weakSelf.view, weakSelf.imageView);
        }
    };
    
    //滑动大图的回调
    _scrollView.itemDidScrollOperationBlock = ^(NSInteger currentIndex) {
        if (currentIndex != _displayIndex) {
             weakSelf.scrollB(weakSelf.imageView);
        }
    };
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
